/*
 * Created on Nov 4, 2003
 *
 * To change the template for this generated file go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
 
package auditoryTree;
//import java.awt.geom.*;
//import java.awt.*;
//import java.awt.*;
import javax.swing.*;
import java.util.*;
//import auditoryUI.AudioBookmark;


/**
 * This class will contain the necessary information for a 
 * SunburstMenu, it will have an arc, and a flag for if it's crossed
 * text info, and icon info, etc.
 * @author shen
 *
 * To change the template for this generated type comment go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
public class AudibleMenuItem{
	
	//private Arc2D moArc;
	private String msName;
	private String msText;
	
	private String msID;
	
	private String msSoundFile;
	
	private ImageIcon moIcon;
	
	private boolean mbCrossed;
	
	private boolean mbEnabled;
	
	private boolean mbHighlight;
	
	private int[][] maSilenceData;
	
    /**
     * @return Returns the maSilenceData.
     */
    public int[][] getSilenceData() {
        return maSilenceData;
    }
    /**
     * @param maSilenceData The maSilenceData to set.
     */
    public void setSilenceData(int[][] maSilenceData) {
        this.maSilenceData = maSilenceData;
    }
	private ArrayList moChildren;
	
	private AudibleMenuItem moParent;
	

	
	//This will be the relative position for this menuItem to it's parent or root
	private int miPosition;
	
	
	
	
	public AudibleMenuItem(){
		
	
		moChildren = new ArrayList();
	
		
	}
	
	
	public AudibleMenuItem(String str){
		msText = str;
		moChildren = new ArrayList();
	}
	
	public AudibleMenuItem add(String str){
		AudibleMenuItem item = new AudibleMenuItem(str);
		addChild(item);
		return item;
	}
	

	
	
	
	public void addChild(AudibleMenuItem item){
		moChildren.add(item);
		item.setParent(this);
	}
	
	public AudibleMenuItem getChildAt(int i){
		if(i >=0 && i < moChildren.size()){
			return (AudibleMenuItem) moChildren.get(i);
		}
		else{
			return null;
		}
	}
	
	public void setParent(AudibleMenuItem parent){
		moParent = parent;
	}
	
	public AudibleMenuItem getParent(){
		return moParent;
	}
	
	/**
	 * get root item for this item
	 * @return
	 */
	public AudibleMenuItem getRoot(){
		if(moParent == null) return this;
		else{
			return moParent.getRoot();
		}
	}
	
	public int getChildCount(){
		return moChildren.size();
	}
	
	/**
	 * get the top level item of this tree
	 * @return
	 */
	public AudibleMenuItem getTopItem(){
		if(getParent() == null) return this;
		else{
			return getParent().getTopItem();
		}
	}
	
	public boolean hasChildren(){
		if(moChildren.size() == 0)return false;
		else return true;
	}
	
	public AudibleMenuItem[] getAllChildren(){
		ArrayList list = new ArrayList();
		_getAllChildren(list);
		Object[] menus = list.toArray();
		AudibleMenuItem[] items = new AudibleMenuItem[menus.length];
		for(int i=0; i< menus.length; i++){
			items[i] = (AudibleMenuItem) menus[i]; 
		}
		return items;
	}
	
	private void _getAllChildren(ArrayList list){
		int size = moChildren.size();
		for(int i =0; i<size; i++){
				AudibleMenuItem item = (AudibleMenuItem) moChildren.get(i); 
				list.add(item);
				item._getAllChildren(list);
		}
	}
	
	/**
	 * This method will return nodes by level
	 * @return
	 */
	public ArrayList getAllChildrenByLevel(){
			ArrayList list = new ArrayList();
			_getAllChildrenByLevel(list);
			return list;
		}
	
	
		private void _getAllChildrenByLevel(ArrayList list){
			int size = moChildren.size();
			ArrayList aLevel = new ArrayList();
			for(int i =0; i<size; i++){
					AudibleMenuItem item = (AudibleMenuItem) moChildren.get(i); 
					aLevel.add(item);
					item._getAllChildrenByLevel(list);
			}
			if(aLevel.size() != 0)
				list.add(aLevel);
		}
	
	/**
	 * @return
	 */
	public boolean isCrossed() {
		return mbCrossed;
	}

	
	/**
	 * @return
	 */
	public String getText() {
		return msText;
	}

	/**
	 * @param b
	 */
	public void setCrossed(boolean b) {
		mbCrossed = b;
	}



	/**
	 * @param string
	 */
	public void setText(String string) {
		msText = string;
	}

	/**
	 * @return
	 */
	public boolean isEnabled() {
		return mbEnabled;
	}

	/**
	 * @param b
	 */
	public void setEnabled(boolean b) {
		mbEnabled = b;
	}

	/**
	 * @return
	 */
	public boolean isHighlight() {
		return mbHighlight;
	}

	/**
	 * @param b
	 */
	public void setHighlight(boolean b) {
		mbHighlight = b;
	}

	
	/**
	 * @return
	 */
	public String getID() {
		return msID;
	}

	/**
	 * @param string
	 */
	public void setID(String string) {
		msID = string;
	}
	
	/**
	 * @return
	 */
	public String getName() {
		return msName;
	}

	/**
	 * @param string
	 */
	public void setName(String string) {
		msName = string;
	}


	/**
	 * @return
	 */
	public int getPosition() {
		return miPosition;
	}

	/**
	 * @param i
	 */
	public void setPosition(int i) {
		miPosition = i;
	}
	

	/**
	 * @return
	 */
	public String getSoundFile(String prefix) {
		return prefix + msSoundFile;
	}

	/**
	 * @param string
	 */
	public void setSoundFile(String string) {
		//set to the complete path here
		//if(prefix == null)
		//	prefix = ".\\ExperimentAudio";
		
	    if(string != null && !string.trim().equals("")){
	    	/*if(string.indexOf(prefix) == -1)
	    		msSoundFile =  prefix+ ""+ string;
	    	else
	    		msSoundFile = string;*/
	    	msSoundFile = string;
	    }
	    else 
	        msSoundFile = null;
	}
}
